﻿Public Class settingsForm

    Private isPasswordOK As Boolean = True

    Private Sub settingsForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadSettings()
    End Sub

    Sub loadSettings()
        '----FTP settings
        txtUserName.Text = My.Settings.ftp_login
        txtPasswd1.Text = My.Settings.ftp_pass
        txtPasswd2.Text = txtPasswd1.Text
        txtFTPSite.Text = My.Settings.ftp_site

        txtFTPMediaDir.Text = My.Settings.ftp_media_dir
        txtFTPExportDir.Text = My.Settings.ftp_export_dir
        txtFTPImportDir.Text = My.Settings.ftp_import_dir

        txtFTPImportFile.Text = My.Settings.ftp_import_file
        txtFTPExportFile.Text = My.Settings.ftp_export_file


        '----www settings
        'txtWWWSite.Text = My.Settings.www_webpage
        txtWWWSite.Text = My.Settings.www_site
        txtWWWAdminRun.Text = My.Settings.www_run
        cntWWWImport.Value = CInt(My.Settings.www_id_importXML)
        cntWWWExport.Value = CInt(My.Settings.www_id_exportXML)



        '----local settings
        txtLOCALbaseDir.Text = My.Settings.local_workPath
        txtLocalMediaDir.Text = My.Settings.uploader_baseDir
        cmbIsMove.Text = CStr(My.Settings.uploader_moveFiles)
        txtlocalMoveMediaToDir.Text = My.Settings.uploader_moveTo
        txtLocalPictLabel.Text = My.Settings.local_workPath

        '---plugins
        txtTinyMceDir.Text = My.Settings.plugin_tinymce_DirThisSystem
        PluginsCheckTINYMCE.Checked = My.Settings.plugin_tinymce

    End Sub
    Sub doSaveSettings()

        My.Settings.ftp_login = txtUserName.Text
        My.Settings.ftp_pass = txtPasswd1.Text
        txtPasswd1.Text = txtPasswd2.Text
        My.Settings.ftp_site = txtFTPSite.Text
        My.Settings.ftp_media_dir = txtFTPMediaDir.Text

        My.Settings.ftp_media_dir = txtFTPMediaDir.Text
        My.Settings.ftp_export_dir = txtFTPExportDir.Text
        My.Settings.ftp_import_dir = txtFTPImportDir.Text

        My.Settings.ftp_import_file = txtFTPImportFile.Text
        My.Settings.ftp_export_file = txtFTPExportFile.Text


        '----www settings
        My.Settings.www_site = txtWWWSite.Text
        My.Settings.www_run = txtWWWAdminRun.Text
        My.Settings.www_id_importXML = CStr(cntWWWImport.Value)
        My.Settings.www_id_exportXML = CStr(cntWWWExport.Value)


        '----local settings
        My.Settings.local_workPath = txtLOCALbaseDir.Text
        My.Settings.uploader_baseDir = txtLocalMediaDir.Text
        My.Settings.uploader_moveFiles = CBool(cmbIsMove.Text)
        My.Settings.uploader_moveTo = txtlocalMoveMediaToDir.Text


        '----plugins
        My.Settings.plugin_tinymce = PluginsCheckTINYMCE.Checked
        My.Settings.plugin_tinymce_DirThisSystem = txtTinyMceDir.Text

    End Sub

    Private Sub txtPasswd2_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPasswd2.KeyUp
        If txtPasswd2.Text.Equals(txtPasswd1.Text) Then
            isPasswordOK = True
            lblPswVerfy.Text = "OK"
            SaveToolStripButton.Enabled = True
        Else
            lblPswVerfy.Text = "No Match"
        End If
    End Sub

    Private Sub txtPasswd1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPasswd1.KeyDown
        isPasswordOK = False
        txtPasswd2.Text = ""
        lblPswVerfy.Text = "New Password"
        SaveToolStripButton.Enabled = False
    End Sub


    Private Sub SaveToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripButton.Click
        doSaveSettings()
        lblToolStrip.Text = "Save OK"

        Timer1.Interval = 4000
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Stop()
        lblToolStrip.Text = ""
    End Sub


    Private Sub PluginsCheckTINYMCE_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PluginsCheckTINYMCE.CheckedChanged
        Dim tempDir As String = Application.StartupPath & My.Settings.plugin_dir & My.Settings.plugin_tinymce_DirStatic
        If PluginsCheckTINYMCE.Checked Then
            My.Settings.plugin_tinymce = True

            If My.Computer.FileSystem.FileExists(tempDir) Then
                LabelTinymce.Text = "'\tinymce\wysiwyg.htm' Exists - WYSIWIG Editor Enabled"
                txtTinyMceDir.Text = tempDir
            Else
                LabelTinymce.Text = "'\tinymce\wysiwyg.htm' does NOT Exists - WYSIWIG Editor Disabled"
                txtTinyMceDir.Text = tempDir
                PluginsCheckTINYMCE.Checked = False
            End If
        Else
            LabelTinymce.Text = "WYSIWIG Editor Disabled " & tempDir
            txtTinyMceDir.Text = String.Empty
        End If
    End Sub
End Class